package com.Final.hj;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.List;

public class FriendNewAdapter extends ArrayAdapter<FriendNewData> {
    private int new_friend_id;
    private Context fContent;
    public FriendNewAdapter(Context content, int newFriendId, List<FriendNewData> friend_add_data){
        super(content, newFriendId, friend_add_data);
        new_friend_id = newFriendId;
        fContent = content;
    }

    @Override
    public View getView(int position, View converView, ViewGroup parent){
        //获取当前滚动实例
        FriendNewData newFriendList = getItem(position);

        View view = LayoutInflater.from(getContext()).inflate(new_friend_id, parent, false);

        ImageView new_f_img = (ImageView) view.findViewById(R.id.new_f_img);
        TextView new_f_uname = (TextView) view.findViewById(R.id.new_f_uname);
        TextView new_f_status = (TextView) view.findViewById(R.id.new_f_status);
        TextView new_f_time = (TextView) view.findViewById(R.id.new_f_time);

        new_f_uname.setText(newFriendList.getMyUname());

        //首先是判断 id是谁的
        //myId 是我的 说明我添加别人的  看status  显示 对方未答复  对方已拒绝  对方已同意
        //否则 根据status 显示 此时可以点击弹窗(同意 拒绝)  我已拒绝  我已同意
        //注意  头像 时间都是显示别人的  只要文字提示不是

        //显示公共信息
        new_f_time.setText(newFriendList.getTime());

        //1 获取myId
        String myId = newFriendList.getIdFlag();
        //获取status
        int status = Integer.parseInt(newFriendList.getStatus());
        //2 比较
        if(myId.equals(newFriendList.getMyId())){
            //我添加别人
            //3 渲染
            new_f_uname.setText(newFriendList.getUname());
            new_f_img.setImageResource(Integer.parseInt(newFriendList.gethImgId()));
            if(status == 1){
                new_f_status.setText("他未答复");
            }else if(status == 2){
                new_f_status.setText("他已同意");
            }else{
                new_f_status.setText("他已拒绝");
            }
        }else{
            //别人加我
            //3 渲染
            new_f_uname.setText(newFriendList.getMyUname());
            new_f_img.setImageResource(Integer.parseInt(newFriendList.getMyHImgId()));
            if(status == 1){
                new_f_status.setText("同意");
            }else if(status == 2){
                new_f_status.setText("我已同意");
            }else{
                new_f_status.setText("我已拒绝");
            }
        }
        //返回view
        return view;
    }
}
